<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('月薪资历史导入')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="modal inmodal fade" id="myModal1" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span>
                </button>
                <h4 class="modal-title">月薪资历史导入</h4>
            </div>
            <div class="modal-body">
                <p>
                    <select id="jsid" name='jsid' class="form-control">
                    </select>
                </p>
            </div>
            <div class="modal-footer">
                <button type="button" id="missmodal1" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" onclick="getJsid()" class="btn btn-primary">确认</button>
            </div>
        </div>
    </div>
</div>
<button type="button" id="modal1" class="btn btn-primary" data-toggle="modal"
        data-target="#myModal1">选择薪资套
</button>


<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                工号：<input type="text" name="badge"/>
                            </li>
                            <li>
                                姓名：<input type="text" name="name"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="synchronization()">
                    <i class="fa fa-plus"></i> 同步薪资历史数据
                </a>
                <a class="btn btn-warning" onclick="exportData()">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-info" onclick="importExcel()">
                    <i class="fa fa-upload"></i> 导入
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>


<script th:inline="javascript">
    var prefix = ctx + "salaryQuery/MonthSalaryHistory";
    var jsid;
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 800) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 350});
        $("#modal1").attr("style", "display:none;");
        getSkypayGroups();
    });


    /**
     * 获取薪资套列表
     */
    function getSkypayGroups() {
        var html = "";
        $.ajax({
            async: false,
            url: prefix + "/getPayGroup",
            data: {},
            type: "post",
            dataType: "json",
            success: function (data) {
                $("#jsid").empty();
                var arry = data;
                for (var i = 0; i < arry.length; i++) {
                    html += "<option value='"
                        + arry[i].id
                        + "'>"
                        + arry[i].title
                        + "</option>";
                }
                $("#jsid").append(html);
                $("#modal1").click();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function getJsid() {
        jsid = $("#jsid").val();
        $("#missmodal1").click();
        getData();
    }

    function getData() {
        var columns = [];
        var other;
        var checkbox = {checkbox: true}
        var badge = {field: 'badge', title: '工号'};
        var name = {field: 'name', title: '姓名'};
        var compName = {field: 'compName', title: '公司'};
        var depName = {field: 'depName', title: '部门'};
        var jobName = {field: 'jobName', title: '岗位'};
        var EmpStartDate = {field: 'EmpStartDate', title: '入职时间'};
        var EmpEndDate = {field: 'EmpEndDate', title: '离职时间'};
        var pcidTitle = {field: 'pcidTitle', title: '薪资城市'};

        columns.push(checkbox, badge, name, compName, depName, jobName, EmpStartDate, EmpEndDate, pcidTitle);

        $.ajax({
            async: false,
            url: prefix + "/findPro",
            data: {"jsid": jsid},
            type: "post",
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    var text = data[i];
                    var field = data[i];
                    other = {
                        field: field, title: text
                    }
                    columns.push(other);
                }
                var options = {
                    code: "id",
                    uniqueId: "id",
                    pagination: false,
                    url: prefix + "/list?jsid=" + jsid,
                    importUrl: prefix + "/importData?jsid=" + jsid,
                    height: $(window).height() - 120,
                    modalName: "月薪资历史",
                    columns: columns
                };
                $.table.init(options);
            },
        });
    }

    function synchronization() {
        if (jsid == undefined || jsid == null || jsid == '') {
            $.modal.alertWarning("未选择薪资套");
            return;
        }

        $.ajax({
            async: false,
            url: prefix + "/synchronization",
            data: {"jsid": jsid},
            type: "post",
            dataType: "text",
            success: function (data) {
                $.modal.alertWarning(data.message);
                $.table.refresh();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function exportData() {
        $.operate.exportData("salaryQuery/MonthSalaryHistory/exportData?jsid=" + jsid, "月薪资历史导出");
    }

    function importExcel() {
        $.table.importExcel()
    }

</script>
</body>
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>

</html>